import request, {pData} from "@/utils/http";
import _ from "lodash";

export default {
    data() {
        return {
            changeAllFloor: pData().changeAllFloor,
            changeEveryFloorInfo: pData().changeEveryFloorInfo,
            floorList: [],
            interNetErr: false,
            showList: [
                {flag:true},
            ]
        }
    },
    methods: {
        changeCarousel(index) {
            this.showList.forEach((it,ix)=>{
                this.showList[ix].flag=false
            })
            this.showList[index].flag=true
        },
        getFloorList(chunkNumber) {
            request('/api/appliedModule/page', {
                params: {
                    bizId: pData().floor,
                    pageSize: 999,
                    pageNum: 1,
                    searchSource: 0
                }
            }).then((data) => {
                if (data.success) {
                    let temp = data.data.records
                    if (temp.length > 0) {
                        let groupedByFloorName = _.groupBy(temp, 'name');
                        let floorSetList = _.map(groupedByFloorName, (group, key) => ({
                            name: key,//之所以加parseInt是因为10F会在1F的前面
                            sortByFloor: parseInt(key),
                            list: _.chain(group)
                                .orderBy(['num'], ['asc']) // 按 num 升序排序
                                .map(item => ({name: item.num, text: item.info}))
                                .value()
                        }));
                        let sortByName = _.orderBy(floorSetList, ['sortByFloor'], ['asc'])
                        for(let item of sortByName){
                            item.finalList=_.chunk(item.list, chunkNumber)
                        }
                        this.floorList = _.chunk(sortByName, 8)
                        for(let i=0;i<this.floorList.length-1;i++){
                            this.showList.push({flag:false})
                        }
                    }
                }
            })
        }
    },
}